package lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestLock {

    // 默认非公平锁，线程插队抢锁
    private static final Lock LOCK = new ReentrantLock();

    public static void main(String[] args) {
        try{
            LOCK.lock();
            try {
                if (LOCK.tryLock(800, TimeUnit.MILLISECONDS)){
                    System.out.println("枷锁成功");
                }else{
                    System.out.println("获取锁失败");
                }
            } catch (InterruptedException e) {
                System.out.println("获取锁失败");
            }
        }finally {
            LOCK.unlock();
        }
    }
}
